package com.example.securityproject.demos.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author: Jiangjb
 * @CreateTime: 2024-04-13  12:43
 * @Description: TODO
 */
public class RegExUtils {

    /**
     * 正则表达式字符串替换
     *
     * @param content   字符串
     * @param pattern   正则表达式
     * @param newString 新的替换字符串
     * @return 返回替换后的字符串
     */
    public static String regReplace(String content, String pattern, String newString) {
        Pattern p = Pattern.compile(pattern);
        Matcher m = p.matcher(content);
        String result = m.replaceAll(newString);
        return result;
    }

    public static String replaceAll(String content, Pattern pattern, String newString) {
        Matcher m = pattern.matcher(content);
        String result = m.replaceAll(newString);
        return result;
    }
}
